package com.ysd.entity;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;

import com.fasterxml.jackson.annotation.JsonIgnore;
@Entity
public class roles {
	@Id
	private String rid;//角色编号
	private String rname;//角色名称 
	private String description;//角色职位
	@JsonIgnore
	 @ManyToMany(fetch=FetchType.EAGER) 
	 @JoinTable(
	 			name="rolemodules",//指定中间表的表名
	 			joinColumns= {@JoinColumn(name="rid")},//维护方实体的外键 
	 			inverseJoinColumns= {@JoinColumn(name="mid")}//被维护方实体的主键 
	 			) 
	 private List<Modules> modules; 
	  
	 	@JsonIgnore
		@ManyToMany(fetch=FetchType.LAZY)
		@JoinTable(
				name="user_roles",
				joinColumns= {@JoinColumn(name="rid")},//操作的主表
				inverseJoinColumns = {@JoinColumn(name="uid")} //操作的从表
				)
		private List<UserInfo> uList;
	 
	 @ManyToMany(fetch=FetchType.LAZY) 
		@JoinTable( 
				name="user_permission",
				joinColumns= {@JoinColumn(name="rid")},//操作的主表
				inverseJoinColumns = {@JoinColumn(name="pid")} //操作的从表
				)
		private List<Permission> pList;

	public roles() {
		super();
		// TODO Auto-generated constructor stub
	}

	public roles(String rid, String rname, String description, List<Modules> modules, List<UserInfo> uList,
			List<Permission> pList) {
		super();
		this.rid = rid;
		this.rname = rname;
		this.description = description;
		this.modules = modules;
		this.uList = uList;
		this.pList = pList;
	}

	@Override
	public String toString() {
		return "roles [rid=" + rid + ", rname=" + rname + ", description=" + description + ", modules=" + modules
				+ ", uList=" + uList + ", pList=" + pList + "]";
	}

	public String getRid() {
		return rid;
	}

	public void setRid(String rid) {
		this.rid = rid;
	}

	public String getRname() {
		return rname;
	}

	public void setRname(String rname) {
		this.rname = rname;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public List<Modules> getModules() {
		return modules;
	}

	public void setModules(List<Modules> modules) {
		this.modules = modules;
	}

	public List<UserInfo> getuList() {
		return uList;
	}

	public void setuList(List<UserInfo> uList) {
		this.uList = uList;
	}

	public List<Permission> getpList() {
		return pList;
	}

	public void setpList(List<Permission> pList) {
		this.pList = pList;
	}
	
}
